package com.ruoyi.pms.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pms.domain.PmsTask;
import com.ruoyi.pms.service.IPmsTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务信息Controller
 *
 * @author huikai
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/pms/task")
public class PmsTaskController extends BaseController
{
    @Autowired
    private IPmsTaskService pmsTaskService;

    /**
     * 查询任务信息列表
     */
    @PreAuthorize("@ss.hasPermi('pms:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmsTask pmsTask)
    {
        startPage();
        List<PmsTask> list = pmsTaskService.selectPmsTaskList(pmsTask);
        return getDataTable(list);
    }

    /**
     * 导出任务信息列表
     */
    @PreAuthorize("@ss.hasPermi('pms:task:export')")
    @Log(title = "任务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsTask pmsTask)
    {
        List<PmsTask> list = pmsTaskService.selectPmsTaskList(pmsTask);
        ExcelUtil<PmsTask> util = new ExcelUtil<PmsTask>(PmsTask.class);
        util.exportExcel(response, list, "任务信息数据");
    }

    /**
     * 获取任务信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") String taskId)
    {
        return success(pmsTaskService.getInfoByTaskId(taskId));
    }

    /**
     * 新增任务信息
     */
    @PreAuthorize("@ss.hasPermi('pms:task:add')")
    @Log(title = "任务信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsTask pmsTask)
    {
        return toAjax(pmsTaskService.add(pmsTask));
    }

    /**
     * 修改任务信息
     */
    @PreAuthorize("@ss.hasPermi('pms:task:edit')")
    @Log(title = "任务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsTask pmsTask)
    {
        return toAjax(pmsTaskService.edit(pmsTask));
    }

    /**
     * 删除任务信息
     */
    @PreAuthorize("@ss.hasPermi('pms:task:remove')")
    @Log(title = "任务信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable String[] taskIds)
    {
        return toAjax(pmsTaskService.removeByTaskIds(taskIds));
    }
}